<%-- 
    Document   : MedVerificacion
    Created on : 14/04/2010, 05:06:19 PM
    Author     : LAPTOP01
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://struts.apache.org/tags-bean"  prefix="bean"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="/tags/c" prefix="c"%>
<%@ include file="seguridad.jsp" %>

<script src="scripts/ajax.js" language="JavaScript"></script>

<html>
    <script LANGUAGE="JavaScript">

      
           

        function meta(cod,idActPer,desc,resp){//por corregir
            var form=document.getElementById("PEIForm");
            var descObj=document.getElementById("descObj").value;
            var descObjE=document.getElementById("descObjEsp").value;
            var idObj=document.getElementById("idObj").value;
            var idObje=document.getElementById("idObje").value;
            form.action="PEI.do?dispatch=listarMAPermanente&cod="+cod+"&desc="+desc+"&resp="+resp+"&descObj="+descObj+"&descObjE="+descObjE+"&idObj="+idObj+"&idObje="+idObje+"&idActPer="+idActPer;
            form.method="post";
            form.submit();
        }

        function contar(texto,e){

            document.getElementById("contador").value=document.getElementById("descActPer").value.length;

            if (texto.length > 500 ) {
                if (navigator.appName == "Netscape") tecla = e.which
                else tecla = e.keyCode
                if (tecla != 8) return false
            }
            return true

        }


        function editar(idact,desc,cod,resp){
            var form = document.getElementById("PEIForm");
            document.getElementById("opcion").value=2;
            document.getElementById("cod").value=cod;
            document.getElementById("idRespon").value=resp;
            document.getElementById("idActPer").value=idact;
            form.descActPer.value = desc;
            document.getElementById("contador").value=desc.length;
        }

        function eliminar(codigo){
            var desc = "desc";
            var respon="0"
            var codObjEsp=document.getElementById("codObjEsp").value;
            var idActPer=0;
            var idDiv = "divTabla";
            var metodo = "GET";
            var tipo = 3;
            var url = "consultasAjax/listarAPermanenteAjax.jsp?desc="+desc+"&codigo="+codigo+"&tipo="+tipo+"&respon="+respon+"&codOEsp="+codObjEsp+"&idActPer="+idActPer;
            var cadenaSalida = "";
            var async = true;
            document.getElementById(idDiv).innerHTML;
            autoCompletarDiv(metodo,url,cadenaSalida,async,idDiv);
        }

        function confirmActionGuardar(){
            if (confirm("Se Guardara los cambios echos en la pantalla  \n ¿Esta seguro de continuar? "))
                return true;
            else
                return false;
        }


        function insertar(){

            if (confirmActionGuardar()==false) return;
            var tipo=document.getElementById("opcion").value;
            var codigo =document.getElementById("cod").value;
            var codObjEsp = document.getElementById("codObjEsp").value;
            var idActPer = document.getElementById("idActPer").value;
            var desc = document.getElementById("descActPer").value;
            var respon =document.getElementById("idRespon").value;
            if(codigo==0){
                var codigo =0;
            }
            var idDiv = "divTabla";
            var metodo = "GET";
            var url = "consultasAjax/listarAPermanenteAjax.jsp?desc="+desc+"&codigo="+codigo+"&tipo="+tipo+"&codOEsp="+codObjEsp+"&respon="+respon+"&idActPer="+idActPer;
            var cadenaSalida = "";
            var async = true;
            document.getElementById(idDiv).innerHTML;
            autoCompletarDiv(metodo,url,cadenaSalida,async,idDiv);
            document.getElementById("opcion").value=1;
            document.getElementById("contador").value="0";
            document.getElementById("idActPer").value="0";
            document.getElementById("descActPer").value="";
            document.getElementById("idRespon").value="-1";
            
        }


        function validar(){


            if (document.getElementById("idActPer").value==""){
                alert("Ingrese la Descripcion de la Actividad Permanente");
                document.getElementById("idActPer").focus();
                return;
            }
            if (document.getElementById("descActPer").value==""){
                alert("Ingrese la Descripcion de la Actividad Permanente");
                document.getElementById("descActPer").focus();
                return;
            }
            if (document.getElementById("idRespon").value==-1){
                alert("seleccione el Responsable de la Actividad");
                document.getElementById("responActPer").focus();
                return;
            }

            insertar();
        }

        function autoCompletarDiv(metodo,url,cadena,async,idDiv)
        {
            if( window.XMLHttpRequest )
                ajax = new XMLHttpRequest(); // No Internet Explorer
            else
                ajax = new ActiveXObject("Microsoft.XMLHTTP");
            ELEMENT_DIV = idDiv;
            // alert("metodo-->>"+metodo+" url-->>"+url+" cadena-->>"+cadena+" async-->"+async+" idDiv-->>"+idDiv)
            ajax.onreadystatechange = funcionCallbackVerDiv;
            //alert("cadena del mal"+cadena);
            ajax.open( metodo, url, async);
            ajax.send(cadena);
        }

        function funcionCallbackVerDiv()
        {
            if( ajax.readyState == 4 )
            {
                if( ajax.status == 200 )
                { //alert(ajax.responseText);
                    document.getElementById(ELEMENT_DIV).innerHTML = ajax.responseText;
                }
            }

        }

           function regresar(){

            var form = document.getElementById("PEIForm");
            var codObj=document.getElementById("codObj").value;
            var idob=document.getElementById("idObj").value;
            var descObj=document.getElementById("descObj").value;

           form.action="PEI.do?dispatch=listarOEspecifico&cod="+codObj+"&desc="+descObj+"&idob="+idob;

            form.method="post";

            form.submit();

        }

        function posicioninicial(){
            document.getElementById("descActPer").focus();
        }

    </script>

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link type="text/css" rel="stylesheet" href="lib/css/Style_Font_Text.css" >
        <link type="text/css" rel="stylesheet" href="lib/css/Style_PageTable.css" >
        <link type="text/css" rel="stylesheet" href="lib/css/Style_Index.css" >

        <title>JSP Page</title>
    </head>
    <body>
        <center>
            <h1 class="substylo">Actividad Estrat&eacute;gica</h1>
            </center>
        <div  style="overflow: auto; width: 710px; height: 400px">

            <table cellpadding="0" cellspacing="0" style="width: 600px; ">
                <tr>
                    <td  align="center">

                        <html:form action="PEI.do?dispatch=ingresarAPermanente" styleId="PEIForm">
                            <html:hidden property="opcion" styleId="opcion" value="1"/>
                            <html:hidden property="codObjEsp"  styleId="codObjEsp"/>
                            <html:hidden property="codObj"  styleId="codObj"/>
                            <input type="hidden"  name="cod"  id="cod"/>
                            <table>
                                <tr>
                                    <td align="left" class="tdLeft">
                                        N&uacute;mero Objetivo
                                        General Estrat&eacute;gico :
                                    </td>
                                    <td align="left">
                                        <html:text  styleId="idObj" property="idObj" maxlength="5" styleClass="text" disabled="true"/>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 150px">
                                        Objetivo Estrat&eacute;gico :
                                    </td>
                                    <td style="width: 400px">
                                        <html:textarea property="descObj" readonly="true" styleId="descObj" disabled="true" rows="5" cols="50" styleClass="textarea"/>
                                    </td>
                                </tr>
                                <tr><td align="left" class="tdLeft">
                                        N&uacute;mero Objetivo Espec&iacute;fico :
                                    </td>
                                    <td align="left">
                                        <html:text  styleId="idObje" property="idObje" maxlength="5" styleClass="text" disabled="true"/>

                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 150px">
                                        Objetivo Espec&iacute;fico :
                                    </td>
                                    <td style="width: 400px">
                                        <html:textarea property="descObjEsp" readonly="true" styleId="descObjEsp" disabled="true" rows="5" cols="50" styleClass="textarea"/><br>
                                    <td>
                                <tr>
                                    <td colspan="2">

                                        <table>
                                            <tr><td align="left" class="tdLeft">
                                        N&uacute;mero Actividad :
                                        </td>
                                        <td align="left">
                                        <html:text  styleId="idActPer" property="idActPer" maxlength="5" styleClass="text"/>

                                        </td>
                                            </tr>
                                            <tr>
                                                <td style="width: 150px">


                                                    Ingresar Actividad Estrat&eacute;gica:
                                                </td>
                                                <td style="width: 400px">
                                                    <html:textarea property="descActPer" styleId="descActPer"  rows="5" cols="50" onkeydown="return contar(this.value,event)" onkeyup="return contar(this.value,event)" styleClass="textarea"/>
                                                    <input type="text" size="2" id="contador"  /><label style="color: #990033" >M&aacute;ximo 500 caracteres</label>

                                                </td>
                                            </tr>
                                            <tr>
                                                <td style="width: 150px">
                                                    Seleccionar Responsable :
                                                </td>
                                                <td style="width: 400px">
                                                    <html:select property="idRespon" styleId="idRespon" styleClass="select">
                                                        <html:option value="-1" >[---------------Seleccionar Responsable-----------]</html:option>
                                                        <html:optionsCollection name="PEIForm" property="listaResponActPer" value="NUM_CODRESP_PK" label="TX_DESCRESP" />
                                                    </html:select>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="2" align="center">
                                                    <input type="button" value="Grabar" onclick="validar()" class="submit2"/>
                                                </td>
                                            </tr>
                                        </table>
                            </table>


                            <br><br>
                            <%int i = 1;%>

                            <logic:present name="PEIForm" property="listaActPer">
                                <div id="divTabla" style="width:100%">
                                    <table id="tabla1" width="99%" align="right" class="userTable">
                                        <tr class="even" align="center">
                                            <th class="textoTR">#</th>
                                            <th class="textoTR">Actividad</th>
                                            <th class="textoTR">Responsable</th>
                                            <th class="textoTR">Editar</th>
                                            <th class="textoTR">Eliminar</th>
                                            <th class="textoTR">meta</th>
                                        </tr>
                                        <logic:iterate name="PEIForm" property="listaActPer" id="lista">
                                            <tr align="center">
                                                <td width="10%" align="center">
                                                    <bean:write name="lista" property="NUM_IDOBJ"/>.<bean:write name="lista" property="NUM_IDOBJESP"/>.<bean:write name="lista" property="NUM_IDACTPER"/>.
                                                </td>

                                                <td style="width:1500px;text-align: left"  align="center">
                                                    <bean:write name="lista" property="TX_DESCACTPER"/>
                                                </td>
                                                <td width="10%" align="center">
                                                    <bean:write name="lista" property="TX_DESCRESP"/>
                                                </td>


                                                <td width="10%" align="center">
                                                    <img style="cursor:pointer" title="Metta" title="Meta" alt="Meta" border=0  src="images/b_edit.png" onclick="editar('<c:out value="${lista.NUM_IDACTPER}"/>','<c:out value="${lista.TX_DESCACTPER}"/>','<c:out value="${lista.NUM_CODACTPER_PK}"/>','<c:out value="${lista.NUM_CODDEPEN_PK}"/>');posicioninicial();">
                                                </td>

                                                <td width="10%" align="center">

                                                    <img style="cursor:pointer" title="Meta" title="Meta" alt="Meta" border=0  src="images/b_drop.png" onclick = "eliminar('<c:out value='${lista.NUM_CODACTPER_PK}'/>');">
                                                </td>
                                                <td width="20%" align="center">

                                                    <img style="cursor:pointer" title="Metta" title="Meta" alt="Meta" border=0  src="images/file_preview.png" onclick="meta('<c:out value='${lista.NUM_CODACTPER_PK}'/>','<c:out value='${lista.NUM_IDACTPER}'/>','<c:out value='${lista.TX_DESCACTPER}'/>','<c:out value='${lista.TX_DESCRESP}'/>');">

                                                </td>
                                            </tr>
                                        </logic:iterate>

                                    </table>

                                </div>
                            </logic:present>
                        </html:form>

                    </td>
                </tr>
                <tr>
                    <td colspan="6" align="center" >
                        <html:button property="button"  value="regresar" onclick="regresar()" styleClass="submit2" />
                    </td>
                </tr>
            </table>
        </div>
    </body>
</html>